<?php
echo "测试数据库连接\n";

$host = '127.0.0.1';
$dbname = 'dyorder';
$username = 'root';
$password = 'root'; // 尝试root密码

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "数据库连接成功\n";
    
    // 检查orders表
    $stmt = $pdo->query('SHOW TABLES LIKE "orders"');
    $tables = $stmt->fetchAll();
    
    if (empty($tables)) {
        echo "orders表不存在\n";
    } else {
        echo "orders表存在\n";
        
        // 检查表结构
        $stmt = $pdo->query('DESCRIBE orders');
        $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
        
        echo "orders表结构:\n";
        foreach ($columns as $column) {
            echo $column['Field'] . "\n";
        }
    }
    
} catch (Exception $e) {
    echo "连接失败: " . $e->getMessage() . "\n";
    
    // 尝试空密码
    try {
        $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, '');
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        echo "使用空密码连接成功\n";
    } catch (Exception $e2) {
        echo "空密码也失败: " . $e2->getMessage() . "\n";
    }
} 